{literal}
<script language="javascript" type="text/javascript">

function popUpWindow(url, widthWin, heightWin, title, parentReload, userLoggedIn) {
	reloadPage = false;
	$("#messageBox").dialog( 'destroy' ).html({/literal}'{capture name="displayJobProgressBar"}<img style="vertical-align: middle;" src="{$GLOBALS.user_site_url}/system/ext/jquery/progbar.gif" alt="[[Please wait ...]]" /> [[Please wait ...]]{/capture}{$smarty.capture.displayJobProgressBar|escape:'quotes'}'{literal});
	$("#messageBox").dialog({
		width: widthWin,
		height: heightWin,
		title: title,
		close: function(event, ui) {
			if (parentReload == true && !userLoggedIn && reloadPage == true) {
				parent.document.location.reload();
			}
		}
	}).dialog( 'open' );

	$.get(url, function(data){
		$("#messageBox").html(data);
	});

	return false;
}
</script>
{/literal}
<br/>
{foreach from=$field_errors item=error key=field_caption}
	{if $error eq 'FILE_NOT_SPECIFIED'}
		<p class="error">'{$field_caption}' [[file not specified]]</p>
	{elseif $error eq 'NOT_SUPPORTED_IMAGE_FORMAT'}
		<p class="error">'{$field_caption}' - [[Image format is not supported]]</p>
	{elseif $error eq 'PICTURES_LIMIT_EXCEEDED'}
		<p class="error">'{$field_caption}' [[limit exceeded]]</p>
	{elseif $error eq 'UPLOAD_ERR_INI_SIZE'}
		<p class="error">[[File size exceeds system limit. Please check the file size limits on your hosting or upload another file.]]</p>
	{elseif $error eq 'UPLOAD_ERR_FORM_SIZE'}
		<p class="error">[[File size exceeds system limit. Please check the file size limits on your hosting or upload another file.]]</p>
	{elseif $error eq 'UPLOAD_ERR_PARTIAL'}
		<p class="error">[[There was an error during file upload]]</p>
	{elseif $error eq 'UPLOAD_ERR_NO_FILE'}
		<p class="error">'{$field_caption}' [[file not specified]]</p>
	{/if}
{/foreach}
{if $errors != ''}
	{foreach from=$errors item=error_message key=error}
		{if $error eq 'WRONG_PARAMETERS_SPECIFIED'}
			<p class="error">[[Wrong parameters are specified]]</p>
		{elseif $error eq 'PARAMETERS_MISSED'}
			<p class="error">[[The key parameters are not specified]]</p>
		{/if}
	{/foreach}
{else}
	{if $number_of_picture < $number_of_picture_allowed}
		<form id="uploadForm" method="post" action="{$GLOBALS.site_url}/manage-pictures/">
			<input type="hidden" name="action" value="add" />
			<input type="hidden" name="listing_sid" value="{$listing.id}" />
			<table>
				<tr>
					<td>[[Caption]]</td>
					<td><input type="text" name="caption" value="" /></td>
				</tr>
				<tr>
					<td>[[Add Picture]]</td>
					<td>
						<input type="file" name="picture" />
						<br /><small>([[max.]] {$uploadMaxFilesize} M)</small>
					</td>
				</tr>
				<tr>
					<td></td>
					<td colspan="2" style="text-align: right;">
						<br/>
						<input type="button" value="[[Add Picture]]" class="grayButton" onclick="uploadPicture();"/>
					</td>
				</tr>
			</table>
		</form>
	{else}
		[[You've reached the limit of number of pictures allowed by your product]]
	{/if}
	<br />
	<table cellpadding="5">
		{if $pictures}
			<tr>
				<td>[[Thumbnail]]</td>
				<td>[[Caption]]</td>
				<td colspan="2">[[Actions]]</td>
			</tr>
			{foreach from=$pictures item=picture name=pictures_block}
				<tr>
					<td><img src="{$picture.thumbnail_url}" alt="" /></td>
					<td>{$picture.caption|truncate:15}</td>
					<td><a href="#" onclick="editPicture({$listing.id}, {$picture.id}); return false;" class="edit"><img src="{$GLOBALS.user_site_url}/templates/_system/main/images/b_edit.gif" border="0" alt="" /></a></td>
					<td><a href="#" onclick="deletePicture({$listing.id}, {$picture.id}); return false;" style="cursor:pointer;"><img src="{$GLOBALS.user_site_url}/templates/_system/main/images/b_drop.gif" /></a></td>
				</tr>
			{/foreach}
		{/if}
	</table>
{/if}
{literal}
<script>

function uploadPicture() {
	var browser = navigator.appName.toLowerCase();
	var options = {
		target: "#UploadPics",
		url:  $("#uploadForm").attr("action") + "?listing_sid=" + {/literal}{$listing.id}{literal},
		beforeSend: function(data) {
			$("#UploadPics").css({"opacity" : "0.3"});
			$("#loading").show();
		},
		success: function(data) {
			$("#UploadPics").css({"opacity" : "1"});
			if ($.browser.msie) {
				data = data.replace(/(\w+)=([^ ">]+)/g, '$1="$2"');
			}
			$("#UploadPics").html(data);
			$("#loading").hide();
	}
	};
	$("#uploadForm").ajaxSubmit(options);
	return false;
}

</script>
{/literal}